package com.sdp.wx.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.sdp.core.bizc.vo.Result;
import com.sdp.right.db.sys_dict.service.ISysDictService;
import com.sdp.right.entity.SysDictItem;
import com.sdp.wx.utils.WxConstants;

@RestController
@RequestMapping("/WxDictController")
public class WxDictController {
	
	@Autowired
	private ISysDictService iSysDictService;

	
	/**
	 * 获取维修类型下拉数据
	 * @return
	 */
	@PostMapping(value = "/queryRepairTypeTree")
	public Result<?> queryRepairTypeTree() {
		List<JSONObject> treeList = new ArrayList<JSONObject>();
		SysDictItem dictItem = null;
		List<Object> objList = iSysDictService.getDictInfo(WxConstants.数据字典_维修类型.getCode(), "");
		for(int i=0;i<objList.size();i++) {
			dictItem = (SysDictItem) objList.get(i);
			JSONObject itemObj = new JSONObject();
			itemObj.put("title", dictItem.getItemText());
			itemObj.put("value", dictItem.getItemValue());
			itemObj.put("key",dictItem.getKeyId());
			treeList.add(itemObj);
		}
		return Result.ok(treeList);
	}
	
	/**
	 * 获取车型下拉数据
	 * @return
	 */
	@PostMapping(value = "/queryVehicleModelTree")
	public Result<?> queryVehicleModelTree() {
		List<JSONObject> treeList = new ArrayList<JSONObject>();
		SysDictItem dictItem = null;
		List<Object> objList = iSysDictService.getDictInfo(WxConstants.数据字典_车型.getCode(), "");
		for(int i=0;i<objList.size();i++) {
			dictItem = (SysDictItem) objList.get(i);
			JSONObject itemObj = new JSONObject();
			itemObj.put("title", dictItem.getItemText());
			itemObj.put("value", dictItem.getItemValue());
			itemObj.put("key",dictItem.getKeyId());
			treeList.add(itemObj);
		}
		return Result.ok(treeList);
	}
}
